package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.AddComment;
import cn.wolfcode.trip.base.mapper.AddCommentMapper;
import cn.wolfcode.trip.base.mapper.StrategyCommentMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IAddCommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AddCommentServiceImpl implements IAddCommentService {
    @Autowired
    private AddCommentMapper addCommentMapper;
    @Autowired
    private StrategyCommentMapper commentMapper;


    @Override
    public void save(AddComment addComment) {
        addComment.setCreateTime(new Date());
        addCommentMapper.insert(addComment);
        Long strategyCommentId = addComment.getStrategyCommentId();
        commentMapper.save(addComment.getId(),strategyCommentId);
    }

    @Override
    public List<AddComment> getAdd(Long commentId) {
        return addCommentMapper.selectAddCommentByCommentId(commentId);
    }

    @Override
    public int getCount(Long commentId) {
        int count = addCommentMapper.getCount(commentId);
        return count;
    }

    @Override
    public PageInfo<AddComment> commentMeList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        return new PageInfo<>(addCommentMapper.commentMeList(qo));
    }
}
